package com.wilmer.testRecords.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.wilmer.common.annotation.Log;
import com.wilmer.common.core.controller.BaseController;
import com.wilmer.common.core.domain.AjaxResult;
import com.wilmer.common.enums.BusinessType;
import com.wilmer.testRecords.domain.YwTestRecords;
import com.wilmer.testRecords.service.IYwTestRecordsService;
import com.wilmer.common.utils.poi.ExcelUtil;
import com.wilmer.common.core.page.TableDataInfo;

/**
 * 随堂测试记录Controller
 * 
 * @author zl
 * @date 2024-04-11
 */
@RestController
@RequestMapping("/testRecords/testRecords")
public class YwTestRecordsController extends BaseController
{
    @Autowired
    private IYwTestRecordsService ywTestRecordsService;

    /**
     * 查询随堂测试记录列表
     */
    @PreAuthorize("@ss.hasPermi('testRecords:testRecords:list')")
    @GetMapping("/list")
    public TableDataInfo list(YwTestRecords ywTestRecords)
    {
        startPage();
        List<YwTestRecords> list = ywTestRecordsService.selectYwTestRecordsList(ywTestRecords);
        return getDataTable(list);
    }

    /**
     * 导出随堂测试记录列表
     */
    @PreAuthorize("@ss.hasPermi('testRecords:testRecords:export')")
    @Log(title = "随堂测试记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, YwTestRecords ywTestRecords)
    {
        List<YwTestRecords> list = ywTestRecordsService.selectYwTestRecordsList(ywTestRecords);
        ExcelUtil<YwTestRecords> util = new ExcelUtil<YwTestRecords>(YwTestRecords.class);
        util.exportExcel(response, list, "随堂测试记录数据");
    }

    /**
     * 获取随堂测试记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('testRecords:testRecords:query')")
    @GetMapping(value = "/{recordId}")
    public AjaxResult getInfo(@PathVariable("recordId") Long recordId)
    {
        return success(ywTestRecordsService.selectYwTestRecordsByRecordId(recordId));
    }

    /**
     * 新增随堂测试记录
     */
    @PreAuthorize("@ss.hasPermi('testRecords:testRecords:add')")
    @Log(title = "随堂测试记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody YwTestRecords ywTestRecords)
    {
        return toAjax(ywTestRecordsService.insertYwTestRecords(ywTestRecords));
    }

    /**
     * 修改随堂测试记录
     */
    @PreAuthorize("@ss.hasPermi('testRecords:testRecords:edit')")
    @Log(title = "随堂测试记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody YwTestRecords ywTestRecords)
    {
        return toAjax(ywTestRecordsService.updateYwTestRecords(ywTestRecords));
    }

    /**
     * 删除随堂测试记录
     */
    @PreAuthorize("@ss.hasPermi('testRecords:testRecords:remove')")
    @Log(title = "随堂测试记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{recordIds}")
    public AjaxResult remove(@PathVariable Long[] recordIds)
    {
        return toAjax(ywTestRecordsService.deleteYwTestRecordsByRecordIds(recordIds));
    }
}
